function varargout = propertyGUI(varargin)
% PROPERTYGUI M-file for propertyGUI.fig
%      PROPERTYGUI, by itself, creates a new PROPERTYGUI or raises the existing
%      singleton*.
%
%      H = PROPERTYGUI returns the handle to a new PROPERTYGUI or the handle to
%      the existing singleton*.
%
%      PROPERTYGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PROPERTYGUI.M with the given input arguments.
%
%      PROPERTYGUI('Property','Value',...) creates a new PROPERTYGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before propertyGUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to propertyGUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help propertyGUI

% Last Modified by GUIDE v2.5 05-Mar-2013 21:43:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @propertyGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @propertyGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before propertyGUI is made visible.
function propertyGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to propertyGUI (see VARARGIN)

%% input (varargin)

AA = varargin{1,1};
handles.AA = AA;

% get input parameters
handles.k   = AA.param.k;
set( handles.edit_k, 'string', num2str(handles.k) )
set( handles.edit_k, 'value', handles.k )
handles.m   = AA.param.m;
set( handles.edit_m, 'string', num2str(handles.m) )
set( handles.edit_m, 'value', handles.m )
handles.L0  = AA.param.l0;
set( handles.edit_L0, 'string', num2str(handles.L0) )
set( handles.edit_L0, 'value', handles.L0 )
handles.aTD = AA.param.aTD;
set( handles.edit_aTD, 'string', num2str(handles.aTD) )
set( handles.edit_aTD, 'value', handles.aTD )

% get input initial conditions
handles.xIC  = AA.state.IC(1);
set( handles.edit_xIC, 'string', num2str(handles.xIC) )
set( handles.edit_xIC, 'value', handles.xIC )
handles.vxIC = AA.state.IC(2);
set( handles.edit_vxIC, 'string', num2str(handles.vxIC) )
set( handles.edit_vxIC, 'value', handles.vxIC )
handles.yIC  = AA.state.IC(3);
set( handles.edit_yIC, 'string', num2str(handles.yIC) )
set( handles.edit_yIC, 'value', handles.yIC )
handles.vyIC = AA.state.IC(4);
set( handles.edit_vyIC, 'string', num2str(handles.vyIC) )
set( handles.edit_vyIC, 'value', handles.vyIC )

% get input initial stance leg (1 = left, 0 = right)
handles.side  = AA.model.stanceleg;
if handles.side == 1
    set(handles.radiobutton_left, 'Value', 1)
    set(handles.radiobutton_right, 'Value', 0)
elseif handles.side == 0
    set(handles.radiobutton_left, 'Value', 0)
    set(handles.radiobutton_right, 'Value', 1)
end

% get input initial footfall
handles.xFP  = AA.env.FP(1);
set( handles.edit_xFP, 'string', num2str(handles.xFP) )
set( handles.edit_xFP, 'value', handles.xFP )
handles.yFP  = AA.env.FP(2);
set( handles.edit_yFP, 'string', num2str(handles.yFP) )
set( handles.edit_yFP, 'value', handles.yFP )


% Choose default command line output for propertyGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes propertyGUI wait for user response (see UIRESUME)
uiwait;


% --- Outputs from this function are returned to the command line.
function varargout = propertyGUI_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
%varargout{1} = handles.output;


%% edit k

function edit_k_Callback(hObject, eventdata, handles)
% hObject    handle to edit_k (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_k as text
%        str2double(get(hObject,'String')) returns contents of edit_k as a double

handles.k = str2double(get(hObject, 'String'));
set( handles.edit_k, 'value', handles.k )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_k_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_k (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit m

function edit_m_Callback(hObject, eventdata, handles)
% hObject    handle to edit_m (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_m as text
%        str2double(get(hObject,'String')) returns contents of edit_m as a double

handles.m = str2double(get(hObject, 'String'));
set( handles.edit_m, 'value', handles.m )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_m_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_m (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit L0

function edit_L0_Callback(hObject, eventdata, handles)
% hObject    handle to edit_L0 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_L0 as text
%        str2double(get(hObject,'String')) returns contents of edit_L0 as a double

handles.L0 = str2double(get(hObject, 'String'));
set( handles.edit_L0, 'value', handles.L0 )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_L0_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_L0 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit aTD

function edit_aTD_Callback(hObject, eventdata, handles)
% hObject    handle to edit_aTD (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_aTD as text
%        str2double(get(hObject,'String')) returns contents of edit_aTD as a double

handles.aTD = str2double(get(hObject, 'String'));
set( handles.edit_aTD, 'value', handles.aTD )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_aTD_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_aTD (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit xIC

function edit_xIC_Callback(hObject, eventdata, handles)
% hObject    handle to edit_xIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_xIC as text
%        str2double(get(hObject,'String')) returns contents of edit_xIC as a double

handles.xIC = str2double(get(hObject, 'String'));
set( handles.edit_xIC, 'value', handles.xIC )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_xIC_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_xIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit vxIC

function edit_vxIC_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vxIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_vxIC as text
%        str2double(get(hObject,'String')) returns contents of edit_vxIC as a double

handles.vxIC = str2double(get(hObject, 'String'));
set( handles.edit_vxIC, 'value', handles.vxIC )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_vxIC_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vxIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit yIC

function edit_yIC_Callback(hObject, eventdata, handles)
% hObject    handle to edit_yIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_yIC as text
%        str2double(get(hObject,'String')) returns contents of edit_yIC as a double

handles.yIC = str2double(get(hObject, 'String'));
set( handles.edit_yIC, 'value', handles.yIC )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_yIC_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_yIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit vyIC

function edit_vyIC_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vyIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_vyIC as text
%        str2double(get(hObject,'String')) returns contents of edit_vyIC as a double

handles.vyIC = str2double(get(hObject, 'String'));
set( handles.edit_vyIC, 'value', handles.vyIC )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_vyIC_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vyIC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit xFP

function edit_xFP_Callback(hObject, eventdata, handles)
% hObject    handle to edit_xFP (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_xFP as text
%        str2double(get(hObject,'String')) returns contents of edit_xFP as a double

handles.xFP = str2double(get(hObject, 'String'));
set( handles.edit_xFP, 'value', handles.xFP )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_xFP_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_xFP (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%% edit yFP

function edit_yFP_Callback(hObject, eventdata, handles)
% hObject    handle to edit_yFP (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_yFP as text
%        str2double(get(hObject,'String')) returns contents of edit_yFP as a double

handles.yFP = str2double(get(hObject, 'String'));
set( handles.edit_yFP, 'value', handles.yFP )

% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_yFP_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_yFP (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%% radio left

% --- Executes on button press in radiobutton_left.
function radiobutton_left_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton_left (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton_left

leftside = get(hObject, 'Value');
if leftside == 1
    set(handles.radiobutton_right, 'Value', 0)
    handles.side = 1;
elseif leftside == 0
    set(handles.radiobutton_right, 'Value', 1)
    handles.side = 0;
end
guidata(hObject, handles);  % update handles


%% radio right

% --- Executes on button press in radiobutton_right.
function radiobutton_right_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton_right (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton_right

rightside = get(hObject, 'Value');
if rightside == 1
    set(handles.radiobutton_left, 'Value', 0)
    handles.side = 0;
elseif rightside == 0
    set(handles.radiobutton_left, 'Value', 1)
    handles.side = 1;
end
guidata(hObject, handles);  % update handles


%% push "set" (varargout) 

% --- Executes on button press in pushbutton_set.
function pushbutton_set_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_set (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% preallocate varargout
BB = handles.AA;

% set output parameters
BB.param.k   = handles.k;
BB.param.m   = handles.m;
BB.param.l0  = handles.L0;
BB.param.aTD = handles.aTD;

% set output initial conditions
BB.state.IC(1) = handles.xIC;
BB.state.IC(2) = handles.vxIC;
BB.state.IC(3) = handles.yIC;
BB.state.IC(4) = handles.vyIC;

% set output initial stance leg (1 = left, 0 = right)
BB.model.stanceleg = handles.side;

% set output initial footfall
BB.env.FP(1) = handles.xFP;
BB.env.FP(2) = handles.yFP;

% output (varargout)
assignin('caller', 'obj', BB);

close


